<?php

namespace app\admin\controller\benefit;

use app\common\controller\AdminController;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\annotation\NodeAnnotation;
use app\Request;
use think\App;
use think\response\Json;
use app\admin\model\BenefitWellNumber;

#[ControllerAnnotation(title: '井号管理')]
class WellNumber extends AdminController
{
    private array $notes;

    protected array $sort = [
        'end_date' => 'desc',
    ];

    #[NodeAnnotation(ignore: ['add', 'delete', 'modify', 'recycle'])]
    protected array $ignoreNode;

    public function __construct(App $app)
    {
        parent::__construct($app);
        self::$model = new BenefitWellNumber();
    }


    #[NodeAnnotation(title: '列表', auth: true)]
    public function index(Request $request): Json|string
    {
        if ($request->isAjax()) {
            if (input('selectFields')) {
                return $this->selectList();
            }
            list($page, $limit, $where) = $this->buildTableParams();
            $count = self::$model::where($where)->count();
            $list  = self::$model::withoutField('password')
                ->where($where)
                ->page($page, $limit)
                ->order($this->sort)
                ->select()->toArray();
            $data  = [
                'code'  => 0,
                'msg'   => '',
                'count' => $count,
                'data'  => $list,
            ];
            return json($data);
        }
        return $this->fetch();
    }
}
